<template>
  <div class="Maintenance">
    <!-- header -->
    <div class="header">
      <h2>车辆费用</h2>
      <div class="buttons">
        <el-button
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click="add"
          >新增</el-button
        >
        <el-button type="primary" icon="el-icon-share"></el-button>
        <el-button type="primary" icon="el-icon-delete"></el-button>
        <el-button type="primary" icon="el-icon-search">搜索</el-button>
        <el-button type="primary">
          上传
          <i class="el-icon-upload el-icon--right"></i
        ></el-button>
      </div>
    </div>
    <!-- header -->
    <!-- table -->
    <el-table
      :data="
        tableData.filter(
          (data) =>
            !search ||
            data.car_number.toLowerCase().includes(search.toLowerCase())
        )
      "
      style="width: 100%"
      height="650"
      border
    >
      <el-table-column type="selection" width="50"> </el-table-column>
      <el-table-column prop="wb_id" label="车辆费用单号" width="165" sortable>
      </el-table-column>
      <el-table-column prop="car_number" label="车牌号" width="165" sortable>
      </el-table-column>
      <el-table-column prop="wb_type" label="登记日期" width="165">
      </el-table-column>
      <el-table-column prop="wb_date" label="修理维护费用" width="165" sortable>
      </el-table-column>
      <el-table-column prop="wb_reason" label="路桥费" width="165">
      </el-table-column>
      <el-table-column prop="wb_reason" label="合计" width="165">
      </el-table-column>
      <el-table-column fixed="right" width="165">
        <template slot="header" slot-scope="">
          <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
        </template>
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">
            查看
          </el-button>
          <el-button type="text" size="small" @click="change(scope.row)"
            >编辑</el-button
          >
          <el-button type="text" size="small" style="color: red" @click="del"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="block">
      <el-pagination background layout="prev, pager, next" :total="1000">
      </el-pagination>
    </div>

    <!-- 分页 -->
    <!-- table -->
    <!-- 详情 -->
    <el-drawer
      title="详情"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="cancel"
      :size="500"
    >
      <div class="details">
        <div class="details-main">
          <!-- ele ui 描述列表 -->
          <div>描述列表</div>
          <el-descriptions title="" direction="vertical" :column="2">
            <el-descriptions-item label="单号">{{
              details.wb_id
            }}</el-descriptions-item>
            <br />
            <el-descriptions-item label="日期">{{
              details.wb_date
            }}</el-descriptions-item>
            <el-descriptions-item label="维保类型">{{
              details.wb_type
            }}</el-descriptions-item>
            <el-descriptions-item label="维保原因">
              {{ details.wb_reason ? "details.wb_reason" : "_" }}
            </el-descriptions-item>
          </el-descriptions>
          <!-- ele ui 描述列表 -->

          <!-- 表单 -->
          <div>表单</div>
          <el-form label-position="top" label-width="80px">
            <el-form-item label="单号">
              {{ details.wb_id }}
            </el-form-item>
            <el-form-item label="日期">
              {{ details.wb_date }}
            </el-form-item>
            <el-form-item label="维保类型">
              {{ details.wb_type }}
            </el-form-item>
            <el-form-item label="维保原因">
              {{ details.wb_reason ? "details.wb_reason" : "_" }}
            </el-form-item>
          </el-form>
          <!-- 表单 -->
        </div>
        <div class="drawer__footer">
          <el-button type="primary" @click="cancel"> 确 定 </el-button>
        </div>
      </div>
    </el-drawer>
    <!-- 详情 -->
    <!-- 添加 -->
    <el-dialog title="新增" :visible.sync="dialogAddVisible">
      <div class="add">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="维保车辆">
            <el-select v-model="form.region" placeholder="请选择">
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="维保时间">
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date1"
                style="width: 100%"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="维保类型">
            <el-checkbox-group v-model="form.type">
              <el-checkbox label="正常维修" name="type"></el-checkbox>
              <el-checkbox label="不常维修" name="type"></el-checkbox>
              <el-checkbox label="异常维修" name="type"></el-checkbox>
              <el-checkbox label="维修" name="type"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="维保原因">
            <el-input type="textarea" v-model="form.desc"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit(form)">提交</el-button>
            <el-button @click="dialogAddVisible = false">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <!-- 添加 -->
    <!-- 编辑 -->
    <el-dialog title="编辑" :visible.sync="dialogChangeVisible">
      <div class="change">
        <el-form ref="details" :model="details" label-width="80px">
          <el-form-item label="维保登记单号" label-width="auto">
            {{ details.wb_id }}
          </el-form-item>
          <el-form-item label="维保车辆">
            <el-select v-model="details.car_number" placeholder="请选择">
              <el-option label="123" value="123"></el-option>
              <el-option label="456" value="456"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="维保时间">
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="details.wb_date"
                style="width: 100%"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="维保类型">
            <el-radio-group v-model="details.wb_type">
              <el-radio label="正常维修" name="正常维修"></el-radio>
              <el-radio label="不常维修" name="不常维修"></el-radio>
              <el-radio label="异常维修" name="异常维修"></el-radio>
              <el-radio label="维修" name="维修"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="维保原因">
            <el-input type="textarea" v-model="details.wb_reason"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit(details)"
              >提交</el-button
            >
            <el-button @click="dialogChangeVisible = false">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <!-- 编辑 -->
  </div>
</template>

<script>
import { wbList } from "../../apis/Maintenance";

export default {
  mounted() {
    //获取json
    wbList().then((ok) => {
      this.tableData = ok.data;
    });
  },
  methods: {
    //编辑
    change(row) {
      this.details = row;
      this.dialogChangeVisible = true;
    },
    //新增提交
    onSubmit(form) {
      console.log("submit!", form);
    },
    //新增
    add() {
      this.dialogAddVisible = true;
    },
    //删除
    del() {},
    //详情取消
    cancel() {
      this.drawer = false;
    },
    // 关闭抽屉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    //查看
    handleClick(row) {
      console.log(row);
      this.drawer = !this.drawer;
      this.details = row;
    },
  },
  data() {
    return {
      // 编辑对话框
      dialogChangeVisible: false,
      //添加对话框
      dialogAddVisible: false,

      //抽屉
      direction: "rtl",
      drawer: false,
      //搜索
      search: "",
      //列表
      tableData: [],
      //详情
      details: {},
      //添加表单
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
    };
  },
};
</script>

<style lang="scss" scoped>
.Maintenance {
  // height: 100%;
  // width: auto;
  // min-width: 444px;
  min-height: 800px;
  background-color: white;
  padding: 10px;
  box-sizing: border-box;
  border-radius: 5px;
  position: relative;

  //头部
  .header {
    h2 {
      margin: 5px 0;
      font-size: 18px;
      font-weight: 400;
    }
    .buttons {
      margin: 20px 0;
    }
  }
  //详情
  .details {
    height: 100%;
    display: flex;
    flex-direction: column;
    .details-main {
      margin-top: 50px;
      padding: 20px;
      flex: 1;
    }
    .drawer__footer {
      display: flex;
      justify-content: center;
    }
  }
  //分页
  .block {
    margin: 10px 0;
  }
}
</style>